//package com.exsun.gateway.jt809.kafka;
//
//import com.exsun.gateway.jt809.common.DevInfoService;
//import com.exsun.gateway.jt809.data.PushData;
//import com.exsun.gateway.jt809.config.NettyClientConfig;
//import com.exsun.gateway.jt809.handler.SendMgrHandler;
//import com.google.gson.reflect.TypeToken;
//import exsun.jt808.data.config.jt808.Jt808ReceiveMsgTopic;
//import exsun.jt808.data.config.jt809.Jt809MsgIdConfig;
//import exsun.jt808.data.jt809_data.BasicVehicleInfo;
//import exsun.jt808.data.jt809_data.vehicledynamic.main.UpExgMsgRegister;
//import exsun.jt808.data.kafka_data.KafkaJT808Data;
//import exsun.jt808.data.upload_data.jt808.TerminalAuthentication;
//import org.apache.kafka.clients.consumer.ConsumerRecord;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.kafka.annotation.KafkaListener;
//import org.springframework.kafka.support.Acknowledgment;
//import org.springframework.stereotype.Service;
//
//import java.lang.reflect.Type;
//import java.util.ArrayList;
//import java.util.List;
//
//@Service
//public class JT809KafkaAuthenticationHandler extends JT809KafkaHandleBase<TerminalAuthentication>{
//    private Logger logger = LoggerFactory.getLogger(JT809KafkaAuthenticationHandler.class);
//    @Autowired
//    private NettyClientConfig nettyClientConfig;
//
//    @Autowired
//    private DevInfoService devInfoService;
//
//    @Autowired
//    private SendMgrHandler sendMgrHandler;
//
//    //订阅终端鉴权数据,上传车辆注册信息
//    @KafkaListener(topics = Jt808ReceiveMsgTopic.terminalAuthentication, containerFactory = "register809Factory")
//    public void batchAuthenticationMsgConsumerListen(List<ConsumerRecord<?, ?>> records, Acknowledgment ack) {
//        try{
//            Type type = new TypeToken<KafkaJT808Data<TerminalAuthentication>>(){}.getType();
//            List<PushData> pushs =  super.done(records, type, (obj)->{
//
//                UpExgMsgRegister upExgMsgRegister = uploadRegisterInfo(obj);
//                byte[] body = sendMgrHandler.jt809Encode.upExgMsgRegister(upExgMsgRegister);
//                PushData pushData = new PushData(Jt809MsgIdConfig.UP_EXG_MSG, body);
//
//                List<PushData> temp = new ArrayList<>();
//                temp.add(pushData);
//                return temp;
//            });
//            //发送错误，则不提交偏移量
//            if(pushs == null)return;
//            if(pushs.size() != 0){
//                logger.info("上报注册：{}条", pushs.size());
//            }
//            ack.acknowledge();
//        }catch(Exception e){
//            logger.info(e.getMessage());
//        }
//    }
//
//    /**
//     * 上传车辆注册
//     *
//     */
//    private UpExgMsgRegister uploadRegisterInfo(TerminalAuthentication data) {
//        //todo 此处需取设备信息
//        //BasicVehicleInfo basicVehicleInfo = devInfoService.getBasicVehicleInfo(data.dvo);
//        BasicVehicleInfo basicVehicleInfo = new BasicVehicleInfo();
//        basicVehicleInfo.setVehicleNo("鄂AMH000");
//        basicVehicleInfo.setVehicleColor(2);
//        UpExgMsgRegister upExgMsgRegister = new UpExgMsgRegister();
//        upExgMsgRegister.setBasicVehicleInfo(basicVehicleInfo);
//        upExgMsgRegister.setProducerId("70316");
//        upExgMsgRegister.setTerminalModelType("YX-GI528");
//        upExgMsgRegister.setTerminalId("6181154");
//        upExgMsgRegister.setTerminalSimCode("120000000001");
//        //平台id
//        upExgMsgRegister.setPlatformId(nettyClientConfig.getPlatformId());
//        return upExgMsgRegister;
//    }
//}
